﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace Convertor.Code.Validation
{
    class WorkSpacePathRule : ValidationRule
    {
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            if (value == null || string.IsNullOrEmpty(value.ToString()))
            {
                return new ValidationResult(false, "IsEmpty");
            }
            else
            {
                try
                {
                    DirectoryInfo df = new DirectoryInfo(value.ToString());
                    if (!df.Exists)
                    {
                        return new ValidationResult(false, "WorkspacePath is not exists.");
                    }
                }
                catch
                {
                    return new ValidationResult(false, "WorkspacePath is mandatory.");
                }
                return new ValidationResult(true, string.Empty);
            }
        }
    }
}
